home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / mpfeel.lha / MPFeel / Plurals / Modules / ring.em < prev    next >
Lisp/Scheme  |  1992-06-04  |  758b  |  38 lines

  1. ;    
  2. ;    Dining Philosophers
  3. ;
  4. ;    File        : ring
  5. ;
  6. ;    Contents    : ring
  7. ;              make-ring
  8. ;
  9. ;    Description    :    The philosophers sit around a circular table.
  10. ;              To this end we create a ring shaped paralation.
  11. ;
  12. ;    Author        : SCM
  13. ;
  14. ;    Change History    :
  15. ;
  16. ;    Date    Name    Comment
  17. ;     13:04:92  SCM     Created
  18.  
  19. (defmodule ring (standard0 ppl plural) ()
  20.  
  21. (defconstant prev 0)
  22. (defconstant next 1)
  23.  
  24. (defun make-ring (circ)
  25.   (let ((new (make-paralation circ))
  26.     (shape-vec (make-vector 2)))
  27.     ((setter vector-ref) shape-vec next
  28.      (match new (elwise (new) (remainder (+ new (- circ 1)) circ))))
  29.     ((setter vector-ref) shape-vec prev
  30.      (match new (elwise (new) (remainder (+ new 1) circ))))
  31.     ((setter shape) new shape-vec)
  32.     new))
  33.  
  34. (export next prev make-ring)
  35. )
  36.  
  37.  
  38.